from multiprocessing import Pool,Queue,Process
import time,os
a = 10
def add(q):
    global a
    print(a,f'add当前进程为{os.getpid()},父进程为{os.getppid()}')
    for i in range(6):
        a+=1
        q.put(a)
        print(a,'add 入栈的值')

def reduce(q):
    global a
    print(a,f'reduce当前进程为{os.getpid()},父进程为{os.getppid()}')
    for i in range(6):
        print(a,'reduce')
        a-=1
        q.put(a)


if __name__ == '__main__':
    start=time.time()
    #  队列上限为5个
    q=Queue(5)
    print("*"*20,start,"*"*20)
    p1=Process(target=add,args=(q,))
    p2=Process(target=reduce,args=(q,))
    q.close()
    #
    p1.start()
    p2.start()
    #
    p1.join()
    p2.join()
    print(time.time()-start)
